package Java241125;

import java.util.Arrays;

public class SeqList {
    private int[] elem;
    private int usedSize;//记录当前顺序表当中 有多少个有效的数据
    private static final int DEFAULT_CAPACITY = 10;
    public SeqList(){
        this.elem =new int[DEFAULT_CAPACITY];
    }
    public void display(){
        for(int i=0;i<this.usedSize;i++){
            System.out.print(this.elem[i]+" ");
        }
        System.out.println();
    }
    //新增元素，默认在数组最后新增
    public void add(int data){
        if(isFull()){
            elem = Arrays.copyOf(elem,elem.length*2);
        }
        this.elem[usedSize] = data;
        usedSize++;
    }
    public boolean isFull(){
        return usedSize==elem.length;
    }
}
class Test1{
    public static void main(String[] args) {
        SeqList seqList = new SeqList();
        seqList.add(1);
        seqList.add(2);
        seqList.add(3);
        seqList.add(4);
        seqList.add(5);
        seqList.add(6);
        seqList.display();
    }
}
